package com.feishi.core.util.javafx;

import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2020-10-31
 * Time: 下午1:55
 */
public class FxUtil {
    public static Parent loadAndStart(String fileName) throws IOException {
        return FXMLLoader.load(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(fileName)));
    }
    public static File openFile(Node node ){
        return openFile(node,null);
    }
    public static File openFile(Node node,String title ){
        Stage stage = (Stage) node.getScene().getWindow();
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);
        return fileChooser.showOpenDialog(stage);
    }
}
